#!/bin/tcsh
#
#  This script runs NWChem on mnemosyne
#
module load mpich
module load nwchem/6.5
#
setenv NWCHEM_PROCS 8
setenv NWCHEM_MEMORY "1200 mb"
setenv NWCHEM_SCRATCH /home/mark/nwchem/scratch
#
set procid=`echo $$`
setenv JOBNAME `ps -p $procid | grep $procid | awk '{print $4}'`
setenv NWCHEM_ROOT `echo $JOBNAME | awk -F_ '{print $1}'`
setenv NWCHEM_SUFFIX `echo $JOBNAME | awk -F_ '{print $2}'`
mkdir $NWCHEM_SCRATCH/$procid
#
# Build the input file
#
cat << finis > $JOBNAME.nw
title "Diamond 3.7 A ball - simulated annealing" 

start  $NWCHEM_ROOT
permanent_dir $cwd
scratch_dir $NWCHEM_SCRATCH/$procid
memory $NWCHEM_MEMORY
ecce_print $JOBNAME.ecce

charge 0

geometry units angstroms noautosym
   C    0.00000    1.78340    1.78340
   C   -0.89170    0.89170    2.67509
   C    1.78340    1.78340    0.00000
   C    0.89170    0.89170    0.89170
   C    2.67509    0.89170   -0.89170
   C    0.00000    0.00000    0.00000
   C    0.00000    0.00000    3.56679
   C    3.56679    0.00000    0.00000
   C   -1.78340    0.00000    1.78340
   C    1.78340    0.00000   -1.78340
   C    1.78340    0.00000    1.78340
   C   -0.89170    2.67509    0.89170
   C    0.89170    2.67509   -0.89170
   C   -0.89170   -0.89170    0.89170
   C    0.89170   -0.89170   -0.89170
   C    0.00000   -1.78340   -1.78340
   C    0.00000   -1.78340    1.78340
   C   -1.78340   -1.78340    0.00000
   C    1.78340   -1.78340    0.00000
   C   -0.89170    0.89170   -0.89170
   C    0.89170    0.89170   -2.67509
   C    0.00000    3.56679    0.00000
   C   -1.78340    1.78340    0.00000
   C   -2.67509    0.89170    0.89170
   C    0.00000    1.78340   -1.78340
   C   -1.78340    0.00000   -1.78340
   C   -3.56679    0.00000    0.00000
   C    0.00000    0.00000   -3.56679
   C    0.89170   -0.89170    2.67509
   C    2.67509   -0.89170    0.89170
   C    0.89170   -2.67509    0.89170
   C    0.00000   -3.56679    0.00000
end

nwpw
  simulation_cell
    boundary_conditions aperiodic
    SC 20.0
  end
  cutoff 10.0
  lmbfgs
  Car-Parrinello
    Nose-Hoover 250.0 3500.0 250.0 3500.0 #Tion=Telc=3500K, relaxation periods=250au
    fake_mass 500.0
    time_step 5.0
    loop 10 100
    scaling 1.0 1.0
    emotion_filename c32.10.emotion
    xyz_filename     c32.10.xyz
  end
end
task pspw energy

set cpmd:init_velocities_temperature 3500.0
task pspw car-parrinello
unset cpmd:init_velocities_temperature

nwpw
  Car-Parrinello
    SA_decay 4.134d4 4.134d4              #decay rate in units of au (1au=4.1889e-17seconds)
    Nose-Hoover 250.0 3500.0 250.0 3500.0 #Tion=Telc=3500K, relaxation periods=250au
    loop 10 500
    emotion_filename c32.11.emotion
    xyz_filename     c32.11.xyz
  end
end
task pspw car-parrinello
task pspw optimize ignore #final optimization
finis
#
#   Run the job
#
mpirun -np $NWCHEM_PROCS nwchem $JOBNAME.nw >& $JOBNAME.nwo
#
#   Clean up scratch directory
rm -rf $NWCHEM_SCRATCH/$procid

